home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 16
/
Mac Magazin and MacEasy Magazine CD - Issue 16.iso
/
Online
/
NetCacheBack 0.9d5 ƒ
/
NetCacheBack source
< prev
next >
Wrap
Text File
|
1995-10-26
|
6KB
|
199 lines
-- Netscape™ Cache Back
-- Copyright © 1995 Mizutori Tetsuya
-- global constants
copy "" to gCurrentFolder
copy {} to gCacheRecordList
tell me to open {}
--
on open (docList)
local currItem
--
if docList is {} then set docList to {(choose file)}
--
tell me to setupConstants by the first item of docList
--
repeat with currItem in docList
tell me to moveCacheFile against currItem
end repeat
end open
to setupConstants by currentFile
global gCurrentFolder, gCacheRecordList
local refFile, cacheRecordList, cachelog, ccacheLog, viewBy
--
tell application "Finder" to get the container of currentFile
copy the result to gCurrentFolder
--
copy ((gCurrentFolder as string) & "Cache log") to cachelog
copy ((gCurrentFolder as string) & "CCache log") to ccacheLog
--
tell application "Finder"
open the gCurrentFolder
set viewBy to the view of the gCurrentFolder
if exists the (alias cachelog) then
if exists the (alias ccacheLog) then
if the modification date of the (alias ccacheLog) comes after ¬
the modification date of the (alias cachelog) then
tell application "NetCacheResolver"
open {(alias ccacheLog)}
quit
end tell
end if
end if
try
set refFile to open for access (alias cachelog)
set cacheRecordList to read refFile as list using delimiters return
close access refFile
tell application "NetCacheResolver"
if the viewBy is byDate then
sort cacheRecordList by date
else if the viewBy is bySize then
sort cacheRecordList by size
else
sort cacheRecordList by name
end if
set gCacheRecordList to the result
quit
end tell
on error
tell me to errorMessage for "Can’t read “Cache log” file"
end try
else if exists the (alias ccacheLog) then
tell application "NetCacheResolver"
if the viewBy is byDate then
resolve {(alias ccacheLog)} with sorted by date
else if the viewBy is bySize then
resolve {(alias ccacheLog)} with sorted by size
else
resolve {(alias ccacheLog)} with sorted by name
end if
set gCacheRecordList to the result
quit
end tell
else
tell me to errorMessage for "Can’t find “Cache log” or “CCache log” file"
end if
end tell
end setupConstants
to moveCacheFile against cacheFile
global gCurrentFolder, gCacheRecordList
local refFile
local cacheRecord, cachefolder, cacheName
local url, urlFolder, urlName
local n
--
tell application "Finder"
copy the container of cacheFile to cachefolder
copy the name of cacheFile to cacheName
end tell
--
set n to 1
repeat with cacheRecord in gCacheRecordList
if cacheName is in the cacheRecord then
tell me to renameCacheFile(cachefolder, cacheName, cacheRecord)
set the item n of gCacheRecordList to ""
exit repeat
end if
set n to n + 1
end repeat
end moveCacheFile
to renameCacheFile(cachefolder, cacheName, cacheRecord)
global gCurrentFolder, gCacheRecordList
local oldDelimiters, cacheItems, cacheFilePath
local url, urlFolder, urlName, urlItems
local targetFolderPath, fileType
--
copy the text item delimiters to oldDelimiters
--
tell me to set the text item delimiters to {tab}
copy every text item in cacheRecord to cacheItems
copy the 6th item of cacheItems to fileType
copy the 5th item of cacheItems to url
tell me to set the text item delimiters to {"/"}
copy every text item in url to urlItems
copy (items 3 through -2 in urlItems) to urlFolder
copy the last item in urlItems to urlName
tell me to set the text item delimiters to {""}
if urlName is "" then set the urlName to "index.html"
if urlName contains "#" then ¬
copy characters 1 thru ((offset of "#" in urlName) - 1) in urlName as string ¬
to urlName
tell me to set the text item delimiters to {":"}
copy ((cachefolder as string) & cacheName) to cacheFilePath
copy ((gCurrentFolder as string) & (urlFolder as string)) to targetFolderPath
tell me to attachFolder at targetFolderPath as string
tell me to setFileAttribute of (alias cacheFilePath) by fileType
tell application "Finder"
try
move alias cacheFilePath to the folder targetFolderPath
if the file urlName in the folder targetFolderPath exists then error
set the name of file cacheName in the folder targetFolderPath to urlName
on error
display dialog "Can’t move “" & cacheName & "” to " & targetFolderPath ¬
buttons {"OK"} default button 1 with icon caution
end try
end tell
--
copy oldDelimiters to the text item delimiters
end renameCacheFile
to attachFolder at pathName -- as string
local listFolders, numbFolders, parentFolder, targetFolder
--
tell application "Finder"
if pathName is "" then
return path to desktop -- case of the Desktop
else if the folder pathName exists then
return the folder pathName -- case of the Folder
else if the disk pathName exists then
return the disk pathName -- case of the Volume
else
--beep
tell me to set the text item delimiters to {":"}
copy every text item of pathName to the listFolders
copy (the count of items in the listFolders) to the numbFolders
if listFolders ends with {""} then ¬
copy the numbFolders - 1 to the numbFolders
copy the item numbFolders in the listFolders to targetFolder
copy (every item in (items 1 thru (numbFolders - 1) in the listFolders)) & {""} ¬
to parentFolder
tell me to attachFolder at the parentFolder as string
make new folder at the result with properties {name:targetFolder}
return the result
end if
end tell
end attachFolder
to setFileAttribute of fileRef by fileType
tell application "Finder"
if fileType contains "text/html" then
set the file type of fileRef to "TEXT"
set the creator type of fileRef to "MOSS"
else if fileType contains "text/plain" then
set the file type of fileRef to "TEXT"
set the creator type of fileRef to "ttxt"
else if fileType contains "image/gif" then
set the file type of fileRef to "GIFf"
set the creator type of fileRef to "JVWR"
else if fileType contains "image/jpeg" then
set the file type of fileRef to "JPEG"
set the creator type of fileRef to "JVWR"
end if
end tell
end setFileAttribute
on errorMessage for errString
error errString
end errorMessage